package com.whros.helloworld;

import com.whros.helloword.plugin.HelloPlugin;
import com.whros.helloword.plugin.PluginInfo;
import com.whros.helloword.plugin.PluginProperties;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import javax.sql.DataSource;
import java.io.*;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author whroid
 * @since 2021-07-25
 */
public class PluginSample {

    public final static void main(String[]  argvs){
        String pluginsPath = "/opt/git/whros/helloworld-language/hello-java/plugins";
        File pluginDir = new File(pluginsPath);
        File[] files = pluginDir.listFiles();
        if(files == null || files.length == 0){
            System.out.println("文件为空");
            return;
        }
        PluginManager pluginManager = new PluginManager();
        PluginConfigMonitor monitor = new PluginConfigMonitor();
        monitor.init(pluginsPath,pluginManager);



        while(true){
            pluginManager.getPluginsMap().forEach((k,v)->{
                HelloPlugin plugin = v.getPlugin();
                System.out.println("plugin:"+plugin.getPluginName() +" version:"+plugin.getPluginVersion());
                plugin.print("key:"+k);
            });

            try {
                Thread.sleep( 10*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }


}
